﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x020003C8 RID: 968
public class DownLoader : LoaderBase
{
	// Token: 0x06001822 RID: 6178 RVA: 0x0009D8E8 File Offset: 0x0009BAE8
	private void Awake()
	{
		this.serverNumText.text = string.Empty;
		this.cacheSizeText.text = "ｷｬｯｼｭ:0MB";
		this.toUploaderButton.onClick.AddListener(new UnityAction(this.SwapToUploader));
		for (int i = 0; i < this.cards.Length; i++)
		{
			int no = i;
			this.cards[i].onValueChanged.AddListener(delegate(bool flag)
			{
				this.OnCardToggle(no, flag);
			});
		}
		this.pageTop.onClick.AddListener(new UnityAction(this.OnClickPageTop));
		this.pagePrev.onClick.AddListener(new UnityAction(this.OnClickPagePrev));
		this.pageNext.onClick.AddListener(new UnityAction(this.OnClickPageNext));
		this.pageLast.onClick.AddListener(new UnityAction(this.OnClickPageLast));
		this.pageInput.onEndEdit.AddListener(new UnityAction<string>(this.OnPageInput));
		DownLoader.SetupDropdownOptions(this.dateSortDropDown, new string[]
		{
			"新しい順",
			"古い順",
			"ランキング（総合）",
			"ランキング（週間）"
		});
		this.dateSortDropDown.onValueChanged.AddListener(delegate(int v)
		{
			this.OnChangeFilter();
		});
		this.handleNameDropDown.onValueChanged.AddListener(delegate(int v)
		{
			this.OnChangeFilter();
		});
		this.maleToggle.onValueChanged.AddListener(delegate(bool v)
		{
			this.OnChangeFilter();
		});
		this.femaleToggle.onValueChanged.AddListener(delegate(bool v)
		{
			this.OnChangeFilter();
		});
		for (int j = 0; j < this.heightToggles.Length; j++)
		{
			this.heightToggles[j].onValueChanged.AddListener(delegate(bool v)
			{
				this.OnChangeFilter();
			});
		}
		for (int k = 0; k < this.bustToggles.Length; k++)
		{
			this.bustToggles[k].onValueChanged.AddListener(delegate(bool v)
			{
				this.OnChangeFilter();
			});
		}
		for (int l = 0; l < this.hairToggles.Length; l++)
		{
			this.hairToggles[l].onValueChanged.AddListener(delegate(bool v)
			{
				this.OnChangeFilter();
			});
		}
		this.downloadButton.onClick.AddListener(new UnityAction(this.OnDownLoad));
		this.deleteButton.onClick.AddListener(new UnityAction(this.OnDelete));
		this.handleNameDropDown.onValueChanged.AddListener(new UnityAction<int>(this.OnChangeUser));
		this.sameUserOtherCharaButton.onClick.AddListener(new UnityAction(this.OnSameUserOtherChara));
		this.deleteCachFileButton.onClick.AddListener(new UnityAction(this.OnDeleteThumbsCache));
		this.clearCheckButton.onClick.AddListener(new UnityAction(this.OnClearCheck));
		this.LoadThumbsCache();
	}

	// Token: 0x06001823 RID: 6179 RVA: 0x0009DC04 File Offset: 0x0009BE04
	private void OnEnable()
	{
		this.GetAllList();
	}

	// Token: 0x06001824 RID: 6180 RVA: 0x0009DC0C File Offset: 0x0009BE0C
	private void OnDestroy()
	{
		this.SaveThumbsCache();
	}

	// Token: 0x06001825 RID: 6181 RVA: 0x0009DC14 File Offset: 0x0009BE14
	private void Update()
	{
		if (this.check != DownLoader.CHECK_STEP.CHECK_NO)
		{
			return;
		}
		if (this.changeFilter)
		{
			this.ChangeFilter();
		}
		this.downloadButton.interactable = (this.selData != null);
		this.deleteButton.interactable = (this.selData != null && this.selData.UserID == this.upDown.UserID);
		this.sameUserOtherCharaButton.interactable = (this.selData != null || this.handleNameDropDown.value == 3);
	}

	// Token: 0x06001826 RID: 6182 RVA: 0x0009DCB0 File Offset: 0x0009BEB0
	private static void SetupDropdownOptions(Dropdown dropDown, string[] names)
	{
		List<Dropdown.OptionData> list = new List<Dropdown.OptionData>();
		for (int i = 0; i < names.Length; i++)
		{
			list.Add(new Dropdown.OptionData(names[i]));
		}
		dropDown.options = list;
	}

	// Token: 0x06001827 RID: 6183 RVA: 0x0009DCEC File Offset: 0x0009BEEC
	private void SetupHandleNameDropDown()
	{
		int num = (this.filterHandleName == null) ? 3 : 4;
		string[] array = new string[num];
		array[0] = "全ての投稿者";
		array[1] = "自分";
		array[2] = "自分以外";
		if (num == 4)
		{
			array[3] = this.filterHandleName;
		}
		DownLoader.SetupDropdownOptions(this.handleNameDropDown, array);
	}

	// Token: 0x06001828 RID: 6184 RVA: 0x0009DD48 File Offset: 0x0009BF48
	private void GetAllList()
	{
		GlobalData.Debug_Log("GetAllList");
		WWWForm wwwform = new WWWForm();
		wwwform.AddField("mode", 7);
		this.netWWW.Post("http://up.illusion.jp/phome_upload/chara/master/unity/getData.php", "キャラリスト取得中...", wwwform, new NetWWW.ActWWW(this.GetAllList_Complete), new NetWWW.ActWWW(this.GetAllList_Faild));
		this.check = DownLoader.CHECK_STEP.CHECK_LIST_WAIT;
	}

	// Token: 0x06001829 RID: 6185 RVA: 0x0009DDA8 File Offset: 0x0009BFA8
	private void GetAllList_Complete(WWW www)
	{
		this.serverDatas.Clear();
		this.userUploadNum.Clear();
		string[] array = www.text.Split(new char[]
		{
			'\n'
		});
		int num = 0;
		int num2 = 0;
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i] == string.Empty)
			{
				break;
			}
			DLDataHeader dldataHeader = this.AnalyzeListData(array[i]);
			if (dldataHeader != null)
			{
				this.serverDatas.Add(dldataHeader);
				if (dldataHeader.Sex == 0)
				{
					num++;
				}
				else
				{
					num2++;
				}
				if (this.userUploadNum.ContainsKey(dldataHeader.HandleName))
				{
					Dictionary<string, int> dictionary;
					string key;
					(dictionary = this.userUploadNum)[key = dldataHeader.HandleName] = dictionary[key] + 1;
				}
				else
				{
					this.userUploadNum.Add(dldataHeader.HandleName, 1);
				}
			}
		}
		Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
		Dictionary<string, string> dictionary3 = new Dictionary<string, string>();
		for (int j = 0; j < this.serverDatas.Count; j++)
		{
			DLDataHeader dldataHeader2 = this.serverDatas[j];
			if (!dictionary2.ContainsKey(dldataHeader2.HandleName))
			{
				dictionary2.Add(dldataHeader2.HandleName, dldataHeader2.UserID);
			}
			if (!dictionary3.ContainsKey(dldataHeader2.UserID))
			{
				dictionary3.Add(dldataHeader2.UserID, dldataHeader2.HandleName);
			}
		}
		this.SetupHandleNameDropDown();
		this.serverNumText.text = string.Concat(new object[]
		{
			"男:",
			num,
			" / 女:",
			num2,
			"\n総キャラ数:",
			this.serverDatas.Count
		});
		Text text = this.serverNumText;
		text.text = text.text + "\nハンドルネーム:" + dictionary2.Count;
		this.check = DownLoader.CHECK_STEP.CHECK_NO;
		this.ChangeFilter();
		this.ChangePage(0, true);
	}

	// Token: 0x0600182A RID: 6186 RVA: 0x0009DFC0 File Offset: 0x0009C1C0
	private DLDataHeader AnalyzeListData(string n)
	{
		string[] array = n.Split(new char[]
		{
			'\t'
		});
		if (string.Empty == array[0])
		{
			return null;
		}
		if (string.Empty == array[2])
		{
			return null;
		}
		if (string.Empty == array[3])
		{
			return null;
		}
		if (string.Empty == array[4])
		{
			return null;
		}
		if (string.Empty == array[5])
		{
			return null;
		}
		if (string.Empty == array[6])
		{
			return null;
		}
		if (string.Empty == array[11])
		{
			return null;
		}
		if (string.Empty == array[15])
		{
			return null;
		}
		int num = int.Parse(array[6]);
		if (num > 0)
		{
			return null;
		}
		DLDataHeader dldataHeader = new DLDataHeader();
		dldataHeader.UID = int.Parse(array[0]);
		dldataHeader.BustSize = int.Parse(array[2]);
		dldataHeader.BustSize = Mathf.Clamp(dldataHeader.BustSize, 0, 2);
		dldataHeader.BHType = int.Parse(array[3]);
		dldataHeader.BHType = Mathf.Clamp(dldataHeader.BHType, 0, 5);
		dldataHeader.Sex = int.Parse(array[4]);
		dldataHeader.Sex = Mathf.Clamp(dldataHeader.Sex, 0, 1);
		dldataHeader.Height = int.Parse(array[5]);
		dldataHeader.Height = Mathf.Clamp(dldataHeader.Height, 0, 2);
		dldataHeader.__State = num;
		dldataHeader.DLCount = int.Parse(array[11]);
		dldataHeader.HandleName = Encoding.UTF8.GetString(Convert.FromBase64String(array[12]));
		dldataHeader.Comment = Encoding.UTF8.GetString(Convert.FromBase64String(array[13]));
		dldataHeader.UserID = array[14];
		dldataHeader.WeekCount = int.Parse(array[15]);
		return dldataHeader;
	}

	// Token: 0x0600182B RID: 6187 RVA: 0x0009E190 File Offset: 0x0009C390
	private void GetAllList_Faild(WWW www)
	{
		this.upDown.ShowMessage("データ一覧の取得に失敗しました");
		this.upDown.ChangeMode(UpDown.MODE.ERROR);
	}

	// Token: 0x0600182C RID: 6188 RVA: 0x0009E1B0 File Offset: 0x0009C3B0
	private void ChangeFilter()
	{
		this.showDatas.Clear();
		DownLoader.USER_FILTERING value = (DownLoader.USER_FILTERING)this.handleNameDropDown.value;
		int num = -1;
		int num2 = -1;
		int num3 = -1;
		int num4 = -1;
		if (this.maleToggle.isOn || this.femaleToggle.isOn)
		{
			num = 0;
			num |= ((!this.maleToggle.isOn) ? 0 : 1);
			num |= ((!this.femaleToggle.isOn) ? 0 : 2);
		}
		if (DownLoader.CheckToggles(this.heightToggles))
		{
			num2 = DownLoader.TogglesFlag(this.heightToggles);
		}
		if (DownLoader.CheckToggles(this.bustToggles))
		{
			num3 = DownLoader.TogglesFlag(this.bustToggles);
		}
		if (DownLoader.CheckToggles(this.hairToggles))
		{
			num4 = DownLoader.TogglesFlag(this.hairToggles);
		}
		for (int i = 0; i < this.serverDatas.Count; i++)
		{
			DLDataHeader dldataHeader = this.serverDatas[i];
			bool flag = true;
			if (value == DownLoader.USER_FILTERING.ME && dldataHeader.UserID != this.upDown.UserID)
			{
				flag = false;
			}
			else if (value == DownLoader.USER_FILTERING.NOT_ME && dldataHeader.UserID == this.upDown.UserID)
			{
				flag = false;
			}
			else if (value == DownLoader.USER_FILTERING.SPECIFIC_USER && dldataHeader.HandleName != this.filterHandleName)
			{
				flag = false;
			}
			if ((num & 1 << dldataHeader.Sex) == 0)
			{
				flag = false;
			}
			if ((num2 != -1 || num3 != -1 || num4 != -1) && dldataHeader.Sex == 0)
			{
				flag = false;
			}
			if (dldataHeader.Sex == 1 && (num2 & 1 << dldataHeader.Height) == 0)
			{
				flag = false;
			}
			else if (dldataHeader.Sex == 1 && (num3 & 1 << dldataHeader.BustSize) == 0)
			{
				flag = false;
			}
			else if (dldataHeader.Sex == 1 && (num4 & 1 << dldataHeader.BHType) == 0)
			{
				flag = false;
			}
			if (flag)
			{
				this.showDatas.Add(dldataHeader);
			}
		}
		if (this.dateSortDropDown.value == 0)
		{
			this.showDatas.Reverse();
		}
		else if (this.dateSortDropDown.value != 1)
		{
			if (this.dateSortDropDown.value == 2)
			{
				this.showDatas.Sort((DLDataHeader a, DLDataHeader b) => b.DLCount - a.DLCount);
			}
			else if (this.dateSortDropDown.value == 3)
			{
				this.showDatas.Sort((DLDataHeader a, DLDataHeader b) => b.WeekCount - a.WeekCount);
			}
		}
		this.changeFilter = false;
		this.ChangePage(0, true);
	}

	// Token: 0x0600182D RID: 6189 RVA: 0x0009E4B0 File Offset: 0x0009C6B0
	private static bool CheckToggles(Toggle[] toggles)
	{
		for (int i = 0; i < toggles.Length; i++)
		{
			if (toggles[i].isOn)
			{
				return true;
			}
		}
		return false;
	}

	// Token: 0x0600182E RID: 6190 RVA: 0x0009E4E4 File Offset: 0x0009C6E4
	private static int TogglesFlag(Toggle[] toggles)
	{
		int num = 0;
		for (int i = 0; i < toggles.Length; i++)
		{
			num |= ((!toggles[i].isOn) ? 0 : (1 << i));
		}
		return num;
	}

	// Token: 0x0600182F RID: 6191 RVA: 0x0009E524 File Offset: 0x0009C724
	private void ChangePage(int newPage, bool forceUpdate)
	{
		if (this.nowPage != newPage || forceUpdate)
		{
			int num = this.PageNum();
			this.nowPage = Mathf.Clamp(newPage, 0, num - 1);
			this.UpdateThumbs(true);
			this.pageInput.text = (this.nowPage + 1).ToString();
			this.pageText.text = " / " + num;
			if (this.selectCard != -1)
			{
				this.cards[this.selectCard].isOn = false;
				this.selectCard = -1;
				this.selData = null;
			}
		}
	}

	// Token: 0x06001830 RID: 6192 RVA: 0x0009E5CC File Offset: 0x0009C7CC
	private void UpdateThumbs(bool requestServer)
	{
		if (this.nowPage == -1)
		{
			return;
		}
		int num = this.nowPage * this.cards.Length;
		int num2 = Mathf.Min(this.showDatas.Count, num + this.cards.Length);
		int num3 = num2 - num;
		List<int> list = new List<int>();
		for (int i = 0; i < this.cards.Length; i++)
		{
			if (num + i < num2)
			{
				this.cards[i].interactable = true;
				int uid = this.showDatas[num + i].UID;
				if (!this.UpdateCardTexture_FromCache(i, uid))
				{
					list.Add(uid);
					this.cards[i].image.sprite = this.loadingSprite;
				}
			}
			else
			{
				this.cards[i].interactable = false;
				this.cards[i].image.sprite = this.noCardSprite;
			}
		}
		if (requestServer && list.Count > 0)
		{
			this.GetThumbs(list);
		}
	}

	// Token: 0x06001831 RID: 6193 RVA: 0x0009E6E4 File Offset: 0x0009C8E4
	private void GetThumbs(List<int> requestIDs)
	{
		this.check = DownLoader.CHECK_STEP.CHECK_THUMBS_WAIT;
		string text = string.Empty;
		for (int i = 0; i < requestIDs.Count; i++)
		{
			text += requestIDs[i];
			text += "\n";
		}
		text = text.TrimEnd(new char[]
		{
			'\n'
		});
		GlobalData.Debug_Log("GetThumbs");
		WWWForm wwwform = new WWWForm();
		wwwform.AddField("mode", 9);
		wwwform.AddField("uid", text);
		this.netWWW.Post("http://up.illusion.jp/phome_upload/chara/master/unity/getData.php", "サムネイル取得中...", wwwform, delegate(WWW www)
		{
			this.GetThumbs_Complete(www, requestIDs);
		}, delegate(WWW www)
		{
			this.upDown.PostError(www, "サムネイルの取得に失敗しました");
		});
	}

	// Token: 0x06001832 RID: 6194 RVA: 0x0009E7BC File Offset: 0x0009C9BC
	private void GetThumbs_Complete(WWW www, List<int> requestIDs)
	{
		this.RecordReceiveThumbs(requestIDs, www.text);
		this.check = DownLoader.CHECK_STEP.CHECK_NO;
		this.UpdateThumbs(false);
	}

	// Token: 0x06001833 RID: 6195 RVA: 0x0009E7DC File Offset: 0x0009C9DC
	private void RecordReceiveThumbs(List<int> requestIDs, string strData)
	{
		string[] array = strData.Split(new char[]
		{
			'\n'
		});
		if (requestIDs.Count != array.Length)
		{
			GlobalData.Debug_LogError("你要的缩略图和你回来的缩略图的数量不对");
			return;
		}
		for (int i = 0; i < requestIDs.Count; i++)
		{
			int id = requestIDs[i];
			byte[] data = Convert.FromBase64String(array[i]);
			this.RecordThumbs(id, data);
		}
		this.UpdateCacheSizeText();
	}

	// Token: 0x06001834 RID: 6196 RVA: 0x0009E84C File Offset: 0x0009CA4C
	private void UpdateCacheSizeText()
	{
		float a = (float)this.cacheSize * 0.001f * 0.001f;
		a = Mathf.Min(a, (float)ConfigData.thumbsCacheSizeMB);
		this.cacheSizeText.text = "ｷｬｯｼｭ:" + a.ToString("0.00") + "MB";
	}

	// Token: 0x06001835 RID: 6197 RVA: 0x0009E8A0 File Offset: 0x0009CAA0
	private Texture2D PNGtoTex(byte[] data)
	{
		Texture2D texture2D = new Texture2D(0, 0, TextureFormat.ARGB32, false);
		texture2D.LoadImage(data);
		return texture2D;
	}

	// Token: 0x06001836 RID: 6198 RVA: 0x0009E8C0 File Offset: 0x0009CAC0
	private bool UpdateCardTexture_FromCache(int cardNo, int dataID)
	{
		Toggle toggle = this.cards[cardNo];
		Image image = toggle.image;
		if (image.sprite != null && image.sprite != this.noCardSprite && image.sprite != this.loadingSprite)
		{
			if (image.sprite.texture != null)
			{
				UnityEngine.Object.Destroy(image.sprite.texture);
			}
			UnityEngine.Object.Destroy(image.sprite);
		}
		byte[] thumbsCach = this.GetThumbsCach(dataID);
		if (thumbsCach != null)
		{
			Vector2 vector = new Vector2(0f, 1f);
			Texture2D texture2D = this.PNGtoTex(thumbsCach);
			Rect rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
			Vector2 pivot = new Vector2(0f, 1f);
			image.sprite = Sprite.Create(texture2D, rect, pivot);
			return true;
		}
		image.sprite = null;
		return false;
	}

	// Token: 0x06001837 RID: 6199 RVA: 0x0009E9C4 File Offset: 0x0009CBC4
	private void RecordThumbs(int id, byte[] data)
	{
		if (this.thumbsCache.ContainsKey(id))
		{
			return;
		}
		long ticks = DateTime.Now.Ticks;
		this.RecordThumbs(id, new ThumbsCacheData(id, data, ticks));
	}

	// Token: 0x06001838 RID: 6200 RVA: 0x0009EA00 File Offset: 0x0009CC00
	private void RecordThumbs(int id, ThumbsCacheData cache)
	{
		if (this.thumbsCache.ContainsKey(id))
		{
			return;
		}
		this.thumbsCache.Add(id, cache);
		this.cacheSize += cache.data.Length;
		int num = this.memoryMaxCacheSizeMB * 1024 * 1024;
		if (this.cacheSize > num)
		{
			this.CacheReduction();
		}
	}

	// Token: 0x06001839 RID: 6201 RVA: 0x0009EA68 File Offset: 0x0009CC68
	private void CacheReduction()
	{
		int num = this.memoryMaxCacheSizeMB * 1024 * 1024;
		int num2 = (int)((float)num * 0.9f);
		List<ThumbsCacheData> list = new List<ThumbsCacheData>();
		foreach (ThumbsCacheData item in this.thumbsCache.Values)
		{
			list.Add(item);
		}
		list.Sort((ThumbsCacheData a, ThumbsCacheData b) => (int)(b.time - a.time));
		this.cacheSize = 0;
		this.thumbsCache.Clear();
		for (int i = 0; i < list.Count; i++)
		{
			this.RecordThumbs(list[i].cardID, list[i]);
			if (this.cacheSize > num2)
			{
				break;
			}
		}
	}

	// Token: 0x0600183A RID: 6202 RVA: 0x0009EB6C File Offset: 0x0009CD6C
	private byte[] GetThumbsCach(int cardID)
	{
		ThumbsCacheData thumbsCacheData = null;
		if (this.thumbsCache.TryGetValue(cardID, out thumbsCacheData))
		{
			long ticks = DateTime.Now.Ticks;
			thumbsCacheData.time = ticks;
			return thumbsCacheData.data;
		}
		return null;
	}

	// Token: 0x0600183B RID: 6203 RVA: 0x0009EBAC File Offset: 0x0009CDAC
	private void SaveThumbsCache()
	{
		if (ConfigData.thumbsCacheSizeMB <= 0)
		{
			return;
		}
		string path = "./UserData/Thumbs/cache.dat";
		string directoryName = Path.GetDirectoryName(path);
		if (!Directory.Exists(directoryName))
		{
			Directory.CreateDirectory(directoryName);
		}
		int num = ConfigData.thumbsCacheSizeMB * 1000 * 1000;
		int num2 = (int)((float)num * 0.9f);
		List<ThumbsCacheData> list = new List<ThumbsCacheData>();
		foreach (ThumbsCacheData item in this.thumbsCache.Values)
		{
			list.Add(item);
		}
		list.Sort((ThumbsCacheData a, ThumbsCacheData b) => (int)(b.time - a.time));
		int num3 = this.hardCacheSplitSizeMB * 1000 * 1000;
		List<int> list2 = new List<int>();
		list2.Add(0);
		int num4 = 0;
		for (int i = 0; i < list.Count; i++)
		{
			int num5 = num4;
			num4 += list[i].data.Length;
			if (num4 > num2)
			{
				list.RemoveRange(i, list.Count - i);
				break;
			}
			if (num4 % num3 < num5 % num3)
			{
				list2.Add(i);
			}
		}
		list2.Add(list.Count);
		for (int j = 0; j < list2.Count - 1; j++)
		{
			int num6 = list2[j];
			int num7 = list2[j + 1] - num6;
			this.SaveThumbsCache_Data(list, num6, num7, j);
		}
	}

	// Token: 0x0600183C RID: 6204 RVA: 0x0009ED6C File Offset: 0x0009CF6C
	private void SaveThumbsCache_Data(List<ThumbsCacheData> datas, int start, int num, int dataNo)
	{
		if (num == 0)
		{
			return;
		}
		string path = "./UserData/Thumbs/cache" + dataNo + ".dat";
		using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
		{
			using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
			{
				binaryWriter.Write(num);
				for (int i = 0; i < num; i++)
				{
					int index = start + i;
					datas[index].Save(binaryWriter);
				}
			}
		}
	}

	// Token: 0x0600183D RID: 6205 RVA: 0x0009EE14 File Offset: 0x0009D014
	private void LoadThumbsCache()
	{
		int num = 0;
		do
		{
			string path = "./UserData/Thumbs/cache" + num + ".dat";
			if (!File.Exists(path))
			{
				break;
			}
			using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
			{
				using (BinaryReader binaryReader = new BinaryReader(fileStream))
				{
					int num2 = binaryReader.ReadInt32();
					for (int i = 0; i < num2; i++)
					{
						ThumbsCacheData thumbsCacheData = new ThumbsCacheData();
						thumbsCacheData.Load(binaryReader);
						this.RecordThumbs(thumbsCacheData.cardID, thumbsCacheData);
					}
				}
			}
			num++;
		}
		while (num < 10000);
		this.UpdateCacheSizeText();
	}

	// Token: 0x0600183E RID: 6206 RVA: 0x0009EEF8 File Offset: 0x0009D0F8
	private void DeleteThumbsCache()
	{
		string[] files = Directory.GetFiles("./UserData/Thumbs/", "*.dat");
		foreach (string path in files)
		{
			File.Delete(path);
		}
		this.cacheSize = 0;
		this.thumbsCache.Clear();
		this.UpdateCacheSizeText();
	}

	// Token: 0x0600183F RID: 6207 RVA: 0x0009EF50 File Offset: 0x0009D150
	private void SelectCard(int no)
	{
		this.selectCard = no;
		this.selData = null;
		if (no != -1)
		{
			int num = no + this.nowPage * this.cards.Length;
			if (num >= 0 && num < this.showDatas.Count)
			{
				this.selData = this.showDatas[num];
			}
		}
		string text = string.Empty;
		if (this.selData != null)
		{
			int num2 = 0;
			this.userUploadNum.TryGetValue(this.selData.HandleName, out num2);
			text = num2.ToString();
		}
		this.handleName.text = ((this.selData == null) ? string.Empty : this.selData.HandleName);
		this.uploadNumText.text = text;
		this.comment.text = ((this.selData == null) ? string.Empty : this.selData.Comment);
	}

	// Token: 0x06001840 RID: 6208 RVA: 0x0009F04C File Offset: 0x0009D24C
	private int PageNum()
	{
		int num = this.showDatas.Count % this.cards.Length;
		num = ((num == 0) ? 0 : 1);
		int a = this.showDatas.Count / this.cards.Length + num;
		return Mathf.Max(a, 1);
	}

	// Token: 0x06001841 RID: 6209 RVA: 0x0009F09C File Offset: 0x0009D29C
	private void DownLoad()
	{
		if (this.selData == null)
		{
			return;
		}
		if (this.downloaded.ContainsKey(this.selData.UID))
		{
			base.ShowMessage("既にダウンロード済みです\u3000ファイル名:" + this.downloaded[this.selData.UID]);
			return;
		}
		GlobalData.Debug_Log("DownLoad");
		WWWForm wwwform = new WWWForm();
		wwwform.AddField("mode", 10);
		wwwform.AddField("pid", this.selData.UID);
		if (this.selData.UserID != this.upDown.UserID)
		{
			wwwform.AddField("dlflag", 1);
		}
		this.netWWW.Post("http://up.illusion.jp/phome_upload/chara/master/unity/getData.php", "ダウンロード中...", wwwform, delegate(WWW www)
		{
			this.DownLoad_Complete(www, this.selData);
		}, delegate(WWW www)
		{
			this.upDown.PostError(www, "ダウンロードに失敗しました");
		});
	}

	// Token: 0x06001842 RID: 6210 RVA: 0x0009F188 File Offset: 0x0009D388
	private void DownLoad_Complete(WWW www, DLDataHeader selData)
	{
		string[] array = new string[]
		{
			"./UserData/Chara/Male/",
			"./UserData/Chara/Female/"
		};
		string[] array2 = new string[]
		{
			"charaM_",
			"charaF_"
		};
		string text = array2[selData.Sex] + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".png";
		string path = array[selData.Sex] + text;
		byte[] buffer = Convert.FromBase64String(www.text);
		using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
		{
			using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
			{
				binaryWriter.Write(buffer);
			}
		}
		this.downloaded.Add(selData.UID, text);
		if (ConfigData.downloadCmpMsg)
		{
			string text2 = "ダウンロードが完了しました\nファイル名:" + text;
			this.upDown.GC.CreateModalMessageUI(text2, new Action<bool>(this.DownLoadCmpMsg), true);
		}
	}

	// Token: 0x06001843 RID: 6211 RVA: 0x0009F2B0 File Offset: 0x0009D4B0
	private void Delete()
	{
		if (this.selData == null)
		{
			return;
		}
		string userID = this.upDown.UserID;
		GlobalData.Debug_Log("Delete");
		WWWForm wwwform = new WWWForm();
		wwwform.AddField("mode", 8);
		wwwform.AddField("pid", this.selData.UID);
		wwwform.AddField("uid", userID);
		this.netWWW.Post("http://up.illusion.jp/phome_upload/chara/master/unity/getData.php", "削除中...", wwwform, delegate(WWW www)
		{
			this.Delete_Complete(www);
		}, delegate(WWW www)
		{
			this.upDown.PostError(www, "削除に失敗しました");
		});
	}

	// Token: 0x06001844 RID: 6212 RVA: 0x0009F344 File Offset: 0x0009D544
	private void Delete_Complete(WWW www)
	{
		base.ShowMessage("削除が完了しました");
		this.GetAllList();
	}

	// Token: 0x06001845 RID: 6213 RVA: 0x0009F358 File Offset: 0x0009D558
	private void DownLoadCmpMsg(bool doNotAgain)
	{
		if (doNotAgain)
		{
			ConfigData.downloadCmpMsg = false;
		}
	}

	// Token: 0x06001846 RID: 6214 RVA: 0x0009F368 File Offset: 0x0009D568
	private void OnCardToggle(int no, bool flag)
	{
		if (flag && no != this.selectCard)
		{
			this.SelectCard(no);
		}
		else if (!flag && no == this.selectCard)
		{
			this.SelectCard(-1);
		}
		SystemSE.Play(SystemSE.SE.CHOICE);
	}

	// Token: 0x06001847 RID: 6215 RVA: 0x0009F3B8 File Offset: 0x0009D5B8
	private void SwapToUploader()
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		this.upDown.ChangeMode(UpDown.MODE.UPLOAD);
	}

	// Token: 0x06001848 RID: 6216 RVA: 0x0009F3CC File Offset: 0x0009D5CC
	private void OnClickPageTop()
	{
		if (this.nowPage != 0)
		{
			SystemSE.Play(SystemSE.SE.CHOICE);
			this.ChangePage(0, false);
		}
	}

	// Token: 0x06001849 RID: 6217 RVA: 0x0009F3E8 File Offset: 0x0009D5E8
	private void OnClickPagePrev()
	{
		if (this.nowPage > 0)
		{
			SystemSE.Play(SystemSE.SE.CHOICE);
			this.ChangePage(this.nowPage - 1, false);
		}
	}

	// Token: 0x0600184A RID: 6218 RVA: 0x0009F40C File Offset: 0x0009D60C
	private void OnClickPageNext()
	{
		if (this.nowPage < this.PageNum() - 1)
		{
			SystemSE.Play(SystemSE.SE.CHOICE);
			this.ChangePage(this.nowPage + 1, false);
		}
	}

	// Token: 0x0600184B RID: 6219 RVA: 0x0009F438 File Offset: 0x0009D638
	private void OnClickPageLast()
	{
		if (this.nowPage != this.PageNum() - 1)
		{
			SystemSE.Play(SystemSE.SE.CHOICE);
			this.ChangePage(this.PageNum() - 1, false);
		}
	}

	// Token: 0x0600184C RID: 6220 RVA: 0x0009F464 File Offset: 0x0009D664
	private void OnChangeFilter()
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		this.changeFilter = true;
	}

	// Token: 0x0600184D RID: 6221 RVA: 0x0009F474 File Offset: 0x0009D674
	private void OnDownLoad()
	{
		SystemSE.Play(SystemSE.SE.YES);
		this.DownLoad();
	}

	// Token: 0x0600184E RID: 6222 RVA: 0x0009F484 File Offset: 0x0009D684
	private void OnDelete()
	{
		SystemSE.Play(SystemSE.SE.YES);
		string text = "選択中のカードを削除します\nよろしいですか？";
		this.upDown.GC.CreateModalYesNoUI(text, new Action(this.Delete), null);
	}

	// Token: 0x0600184F RID: 6223 RVA: 0x0009F4BC File Offset: 0x0009D6BC
	private void OnSameUserOtherChara()
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		if (this.selData != null && this.handleNameDropDown.value != 3)
		{
			this.filterHandleName = this.selData.HandleName;
			this.SetupHandleNameDropDown();
			this.handleNameDropDown.value = 3;
			this.changeFilter = true;
		}
		else if (this.handleNameDropDown.value == 3)
		{
			this.filterHandleName = null;
			this.SetupHandleNameDropDown();
			this.handleNameDropDown.value = 0;
			this.changeFilter = true;
		}
	}

	// Token: 0x06001850 RID: 6224 RVA: 0x0009F54C File Offset: 0x0009D74C
	private void OnChangeUser(int no)
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		Text componentInChildren = this.sameUserOtherCharaButton.GetComponentInChildren<Text>();
		componentInChildren.text = ((no != 3) ? "この投稿者のキャラをみる" : "全ての投稿者のキャラをみる");
	}

	// Token: 0x06001851 RID: 6225 RVA: 0x0009F588 File Offset: 0x0009D788
	private void OnPageInput(string str)
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		try
		{
			int num = int.Parse(str);
			this.ChangePage(num - 1, false);
		}
		catch
		{
			this.pageInput.text = (this.nowPage + 1).ToString();
		}
	}

	// Token: 0x06001852 RID: 6226 RVA: 0x0009F5E8 File Offset: 0x0009D7E8
	private void OnDeleteThumbsCache()
	{
		SystemSE.Play(SystemSE.SE.YES);
		string text = "サムネイルキャッシュを削除します\nよろしいですか？";
		this.upDown.GC.CreateModalYesNoUI(text, new Action(this.DeleteThumbsCache), null);
	}

	// Token: 0x06001853 RID: 6227 RVA: 0x0009F620 File Offset: 0x0009D820
	private void OnClearCheck()
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		this.maleToggle.isOn = false;
		this.femaleToggle.isOn = false;
		for (int i = 0; i < this.heightToggles.Length; i++)
		{
			this.heightToggles[i].isOn = false;
		}
		for (int j = 0; j < this.bustToggles.Length; j++)
		{
			this.bustToggles[j].isOn = false;
		}
		for (int k = 0; k < this.hairToggles.Length; k++)
		{
			this.hairToggles[k].isOn = false;
		}
	}

	// Token: 0x04001B78 RID: 7032
	private const string MSG_GetAllList = "キャラリスト取得中...";

	// Token: 0x04001B79 RID: 7033
	private const string MSG_GetThumbs = "サムネイル取得中...";

	// Token: 0x04001B7A RID: 7034
	private const string MSG_DownLoad = "ダウンロード中...";

	// Token: 0x04001B7B RID: 7035
	private const string MSG_Delete = "削除中...";

	// Token: 0x04001B7C RID: 7036
	private DownLoader.CHECK_STEP check;

	// Token: 0x04001B7D RID: 7037
	[SerializeField]
	private Toggle[] cards;

	// Token: 0x04001B7E RID: 7038
	[SerializeField]
	private Text serverNumText;

	// Token: 0x04001B7F RID: 7039
	[SerializeField]
	private Text cacheSizeText;

	// Token: 0x04001B80 RID: 7040
	[SerializeField]
	private Button toUploaderButton;

	// Token: 0x04001B81 RID: 7041
	[SerializeField]
	private Text handleName;

	// Token: 0x04001B82 RID: 7042
	[SerializeField]
	private Text uploadNumText;

	// Token: 0x04001B83 RID: 7043
	[SerializeField]
	private Text comment;

	// Token: 0x04001B84 RID: 7044
	[SerializeField]
	private Button pageTop;

	// Token: 0x04001B85 RID: 7045
	[SerializeField]
	private Button pagePrev;

	// Token: 0x04001B86 RID: 7046
	[SerializeField]
	private Button pageNext;

	// Token: 0x04001B87 RID: 7047
	[SerializeField]
	private Button pageLast;

	// Token: 0x04001B88 RID: 7048
	[SerializeField]
	private Text pageText;

	// Token: 0x04001B89 RID: 7049
	[SerializeField]
	private InputField pageInput;

	// Token: 0x04001B8A RID: 7050
	[SerializeField]
	private Dropdown dateSortDropDown;

	// Token: 0x04001B8B RID: 7051
	[SerializeField]
	private Dropdown handleNameDropDown;

	// Token: 0x04001B8C RID: 7052
	[SerializeField]
	private Toggle maleToggle;

	// Token: 0x04001B8D RID: 7053
	[SerializeField]
	private Toggle femaleToggle;

	// Token: 0x04001B8E RID: 7054
	[SerializeField]
	private Toggle[] heightToggles = new Toggle[3];

	// Token: 0x04001B8F RID: 7055
	[SerializeField]
	private Toggle[] bustToggles = new Toggle[3];

	// Token: 0x04001B90 RID: 7056
	[SerializeField]
	private Toggle[] hairToggles = new Toggle[6];

	// Token: 0x04001B91 RID: 7057
	[SerializeField]
	private Button clearCheckButton;

	// Token: 0x04001B92 RID: 7058
	[SerializeField]
	private Button sameUserOtherCharaButton;

	// Token: 0x04001B93 RID: 7059
	[SerializeField]
	private Button downloadButton;

	// Token: 0x04001B94 RID: 7060
	[SerializeField]
	private Button deleteButton;

	// Token: 0x04001B95 RID: 7061
	[SerializeField]
	private Sprite noCardSprite;

	// Token: 0x04001B96 RID: 7062
	[SerializeField]
	private Sprite loadingSprite;

	// Token: 0x04001B97 RID: 7063
	[SerializeField]
	private Button deleteCachFileButton;

	// Token: 0x04001B98 RID: 7064
	private List<DLDataHeader> serverDatas = new List<DLDataHeader>();

	// Token: 0x04001B99 RID: 7065
	private Dictionary<string, int> userUploadNum = new Dictionary<string, int>();

	// Token: 0x04001B9A RID: 7066
	private List<DLDataHeader> showDatas = new List<DLDataHeader>();

	// Token: 0x04001B9B RID: 7067
	private DLDataHeader selData;

	// Token: 0x04001B9C RID: 7068
	private int selectCard = -1;

	// Token: 0x04001B9D RID: 7069
	private int nowPage = -1;

	// Token: 0x04001B9E RID: 7070
	private Dictionary<int, ThumbsCacheData> thumbsCache = new Dictionary<int, ThumbsCacheData>();

	// Token: 0x04001B9F RID: 7071
	private int cacheSize;

	// Token: 0x04001BA0 RID: 7072
	private bool changeFilter;

	// Token: 0x04001BA1 RID: 7073
	private string filterHandleName;

	// Token: 0x04001BA2 RID: 7074
	private Dictionary<int, string> downloaded = new Dictionary<int, string>();

	// Token: 0x04001BA3 RID: 7075
	private int memoryMaxCacheSizeMB = 1000;

	// Token: 0x04001BA4 RID: 7076
	private int hardCacheSplitSizeMB = 100;

	// Token: 0x020003C9 RID: 969
	private enum HAIR_TYPE
	{
		// Token: 0x04001BAA RID: 7082
		SHORT,
		// Token: 0x04001BAB RID: 7083
		SEMI_LONG,
		// Token: 0x04001BAC RID: 7084
		LONG,
		// Token: 0x04001BAD RID: 7085
		PONY,
		// Token: 0x04001BAE RID: 7086
		TWIN,
		// Token: 0x04001BAF RID: 7087
		OTHER,
		// Token: 0x04001BB0 RID: 7088
		NUM
	}

	// Token: 0x020003CA RID: 970
	private enum CHECK_STEP
	{
		// Token: 0x04001BB2 RID: 7090
		CHECK_NO,
		// Token: 0x04001BB3 RID: 7091
		CHECK_LIST_WAIT,
		// Token: 0x04001BB4 RID: 7092
		CHECK_THUMBS_WAIT
	}

	// Token: 0x020003CB RID: 971
	private enum SORT
	{
		// Token: 0x04001BB6 RID: 7094
		NEW,
		// Token: 0x04001BB7 RID: 7095
		OLD,
		// Token: 0x04001BB8 RID: 7096
		RANK_TOTAL,
		// Token: 0x04001BB9 RID: 7097
		RANK_WEEK,
		// Token: 0x04001BBA RID: 7098
		NUM
	}

	// Token: 0x020003CC RID: 972
	private enum USER_FILTERING
	{
		// Token: 0x04001BBC RID: 7100
		ALL,
		// Token: 0x04001BBD RID: 7101
		ME,
		// Token: 0x04001BBE RID: 7102
		NOT_ME,
		// Token: 0x04001BBF RID: 7103
		SPECIFIC_USER
	}
}
